package logic

import (
	"context"
	"house/models"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseLogic {
	return &CreateHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源发布权限
func (l *CreateHouseLogic) CreateHouse(in *house.CreateHouseReq) (*house.CreateHouseResp, error) {
	// todo: 房源发布
	var err error
	h := models.House{
		UserId:  int(in.UserId),
		City:    in.City,
		Address: in.Address,
		Floor:   in.Floor,
		Size:    float64(in.Size),
		Price:   int(in.Price),
		Info:    in.Info,
		Status:  int(in.Status),
	}
	err = h.Create()
	if err != nil {
		logx.Error("房源发布失败", err)
		return nil, err
	}

	return &house.CreateHouseResp{
		Id: int64(h.ID),
	}, nil
}
